// Kony


#include "AbilitySystem/ModMagCalc/MMC_MaxHealth.h"

#include "AbilitySystem/BaseAttributeSet.h"
#include "Interaction/CombatInterface.h"

UMMC_MaxHealth::UMMC_MaxHealth()
{
	//获取体魄属性
	VigorDef.AttributeToCapture = UBaseAttributeSet::GetVigorAttribute();
	//获取属性捕获源
	VigorDef.AttributeSource = EGameplayEffectAttributeCaptureSource::Target;
	//设置快照
	VigorDef.bSnapshot = false;
	//将属性定义添加到相关属性捕获列表中
	RelevantAttributesToCapture.Add(VigorDef);

	StrengthDef.AttributeToCapture = UBaseAttributeSet::GetStrengthAttribute();
	StrengthDef.AttributeSource = EGameplayEffectAttributeCaptureSource::Target;
	StrengthDef.bSnapshot = false;
	RelevantAttributesToCapture.Add(StrengthDef);
}

float UMMC_MaxHealth::CalculateBaseMagnitude_Implementation(const FGameplayEffectSpec& Spec) const
{
	//从源和目标收集标签 Gather tags from source and target
	const FGameplayTagContainer* SourceTags = Spec.CapturedSourceTags.GetAggregatedTags();
	//目标获取
	const FGameplayTagContainer* TargetTags = Spec.CapturedTargetTags.GetAggregatedTags();

	// 创建聚合器评估参数
	FAggregatorEvaluateParameters EvaluationParameters;
	// 设置源标签
	EvaluationParameters.SourceTags = SourceTags;
	// 设置目标标签
	EvaluationParameters.TargetTags = TargetTags;

	float Vigor = 0.f;
	float Strength = 0.f;
	//获取目标上的 体魄属性值 写入到上面的 Vigor变量中
	GetCapturedAttributeMagnitude(VigorDef, Spec, EvaluationParameters, Vigor);
	Vigor = FMath::Max<float>(Vigor, 0.f); //设置如果小于0 则为0
	GetCapturedAttributeMagnitude(VigorDef, Spec, EvaluationParameters, Strength);
	Strength = FMath::Max<float>(Strength, 0.f); //设置如果小于0 则为0
	int32 PlayerLevel = 1;
	if (Spec.GetContext().GetSourceObject()->Implements<UCombatInterface>())
	{
		//获取等级
		PlayerLevel = ICombatInterface::Execute_GetPlayerLevel(Spec.GetContext().GetSourceObject());
	}
	// //获取源对象 战斗接口 这是旧版获取
	// ICombatInterface* CombatInterface = Cast<ICombatInterface>(Spec.GetContext().GetSourceObject());
	// //获取等级
	// const int32 PlayerLevel = CombatInterface->GetPlayerLevel();
	//返回 根据公式计算后的 最大生命值
	return  1.f * Vigor + 0.5f * Strength + 5.f * PlayerLevel;
}
